package com.sc.study.sleeproom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sc.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.sleeproom.domain.ScSleepRoomPerson;
import com.sc.study.sleeproom.service.IScSleepRoomPersonService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 寝室人员Controller
 * 
 * @author sc
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/study/sleeproomperson")
public class ScSleepRoomPersonController extends BaseController
{
    @Autowired
    private IScSleepRoomPersonService scSleepRoomPersonService;

    /**
     * 查询寝室人员列表 分页
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScSleepRoomPerson scSleepRoomPerson)
    {
        startPage();
        List<ScSleepRoomPerson> list = scSleepRoomPersonService.selectScSleepRoomPersonList(scSleepRoomPerson);
        return getDataTable(list);
    }

    /**
     * 查询寝室人员列表 不包含老师 不分页
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:list')")
    @GetMapping("/listNotPage")
    public AjaxResult listNotPage(ScSleepRoomPerson scSleepRoomPerson)
    {
        List<ScSleepRoomPerson> list = scSleepRoomPersonService.selectScSleepRoomPersonNotTeacherList(scSleepRoomPerson);
        return AjaxResult.success(list);
    }

    /**
     * 导出寝室人员列表
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:export')")
    @Log(title = "寝室人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScSleepRoomPerson scSleepRoomPerson)
    {
        List<ScSleepRoomPerson> list = scSleepRoomPersonService.selectScSleepRoomPersonList(scSleepRoomPerson);
        ExcelUtil<ScSleepRoomPerson> util = new ExcelUtil<ScSleepRoomPerson>(ScSleepRoomPerson.class);
        util.exportExcel(response, list, "寝室人员数据");
    }

    /**
     * 获取寝室人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scSleepRoomPersonService.selectScSleepRoomPersonById(id));
    }

    /**
     * 新增寝室人员
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:add')")
    @Log(title = "寝室人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScSleepRoomPerson scSleepRoomPerson)
    {
        scSleepRoomPerson.setIntime(DateUtils.getLocalDateTime());
        return toAjax(scSleepRoomPersonService.insertScSleepRoomPerson(scSleepRoomPerson));
    }

    /**
     * 批量新增寝室人员
     * @param scSleepRoomPersons
     * @return
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:add')")
    @Log(title = "寝室人员", businessType = BusinessType.INSERT)
    @PostMapping("/batch/student")
    public AjaxResult batchStudent(@RequestBody ScSleepRoomPerson[] scSleepRoomPersons)
    {
        return toAjax(scSleepRoomPersonService.batchStudent(scSleepRoomPersons));
    }

    /**
     * 修改寝室人员
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:edit')")
    @Log(title = "寝室人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScSleepRoomPerson scSleepRoomPerson)
    {
        return toAjax(scSleepRoomPersonService.updateScSleepRoomPerson(scSleepRoomPerson));
    }

    /**
     * 删除寝室人员
     */
    @PreAuthorize("@ss.hasPermi('study:sleeproomperson:remove')")
    @Log(title = "寝室人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scSleepRoomPersonService.deleteScSleepRoomPersonByIds(ids));
    }
}
